<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Homepage</title>
    </h:head>
    <h:body>
        
        Logged user: #{userBean.name}<br/>
        <p:link outcome="notifications" value="notifications"/> <h:outputText value=" there is a new notify!!!" rendered="#{notificationView.flagnotify}"/> <br />
        <p:link outcome="settings" value="settings"/><br />
        <h:form>
            <p:commandLink action="#{loginBean.logout()}" value="logout"/>
        </h:form>
        
        <br /><br /> 
        
        <br /><br /> 
        
 
     
        <h:form id="search">
            <h:panelGrid columns="6" id="searchGrid">
                <p:inputText id="searchBar" value="#{researchBean.user.email}"/>
                <p:commandButton id="search" value="Search"  update=":calendar:schedule,searchGrid"
                                 action="#{calendarBean.search()}" />
                <p:commandButton id="return" value="Come back at your calendar" update=":calendar:schedule, searchGrid"
                                 action="#{calendarBean.resetSearch()}" rendered="#{calendarBean.searched}"/>
                 <p:commandButton id="requestfriendship" value="add to friend" update="searchGrid"
                                  action="#{calendarBean.sendRequest()}" rendered="#{!calendarBean.friend and calendarBean.searched and !calendarBean.pending and !calendarBean.response}"/>
                 <h:outputText id="pendingrequest" value="pendind request"
                               rendered="#{calendarBean.pending and calendarBean.searched}"/>
                 <p:commandButton id="acceptfriendshiprequest" value="accept friend" update="searchGrid"
                                  action="#{calendarBean.accetta()}" rendered="#{calendarBean.response and calendarBean.searched}"/>
                 <p:commandButton id="declinefriendshiprequest" value="decline request" update="searchGrid"
                                  action="#{calendarBean.rifiuta()}" rendered="#{calendarBean.response and calendarBean.searched}"/>
            </h:panelGrid>
        </h:form>
        <h:form id="calendar">
            <p:growl id="messages" showDetail="true" />   
        <p:schedule id="schedule" value="#{calendarBean.eventModel}" widgetVar="myschedule" timeZone="GMT+1">
            <p:ajax event="dateSelect" listener="#{calendarBean.onDateSelect}" update="eventDetails" oncomplete="PF('eventDialog').show();" disabled="#{calendarBean.searched}"/>
            <p:ajax event="eventSelect" listener="#{calendarBean.onEventSelect}" update="eventDetails" oncomplete="PF('eventDialog').show();" disabled="#{not calendarBean.visible}"/>
            <p:ajax event="eventMove" listener="#{calendarBean.onEventMove}" update="messages" disabled="#{calendarBean.searched}"/>
            <p:ajax event="eventResize" listener="#{calendarBean.onEventResize}" update="messages" disabled="#{calendarBean.searched}"/>
        </p:schedule>
            
        
        <p:dialog widgetVar="eventDialog" header="Event Details" showEffect="clip" hideEffect="clip">
            <h:panelGrid id="eventDetails" columns="3">
            <h:outputLabel for="title" value="Title:" />
            <p:inputText id="title" value="#{calendarBean.event.title}" required="true" rendered="#{not calendarBean.searched and calendarBean.event.editable}" /> 
            <h:outputText value="#{calendarBean.event.title}" rendered="#{(calendarBean.event.visibility and calendarBean.searched) or not calendarBean.event.editable}" />
            <h:outputText value="Not Visible" rendered="#{not calendarBean.event.visibility and calendarBean.searched}" />
            <p:message for="title" /> 
            
            <h:outputLabel for="from" value="Start Time:" />
            <p:inputMask id="from" value="#{calendarBean.event.startDate}" mask="99/99/9999" rendered="#{not calendarBean.searched and calendarBean.event.editable}" >
                <f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT+1"/>
            </p:inputMask>            
            <h:outputText value="#{calendarBean.event.startDate}" rendered="#{(calendarBean.event.visibility and calendarBean.searched) or not calendarBean.event.editable}" >
                <f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT+1"/>
            </h:outputText>
            <h:outputText value="Not Visible" rendered="#{not calendarBean.event.visibility and calendarBean.searched}" />
            <p:message for="from" /> 
            
            <h:outputLabel for="to" value="End Time:" />
            <p:inputMask id="to" value="#{calendarBean.event.endDate}" mask="99/99/9999" rendered="#{not calendarBean.searched and calendarBean.event.editable}" >
                <f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT+1"/>
            </p:inputMask>             
            <h:outputText value="#{calendarBean.event.endDate}" rendered="#{(calendarBean.event.visibility and calendarBean.searched) or not calendarBean.event.editable}" >
                <f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT+1"/>
            </h:outputText>
            <h:outputText value="Not Visible" rendered="#{not calendarBean.event.visibility and calendarBean.searched}" />
            <p:message for="to" />
            
            <h:outputLabel for="location" value="Location:" />
            <p:inputText id="location" value="#{calendarBean.event.location}" required="true" rendered="#{not calendarBean.searched and calendarBean.event.editable}" />
            <h:outputText value="#{calendarBean.event.location}" rendered="#{(calendarBean.event.visibility and calendarBean.searched) or not calendarBean.event.editable}" />
            <h:outputText value="Not Visible" rendered="#{not calendarBean.event.visibility and calendarBean.searched}" />
            <p:message for="location" /> 
            
            <h:outputLabel for="outdoor" value="Outdoor:" />
            <h:selectBooleanCheckbox id="outdoor" value="#{calendarBean.event.outdoor}" disabled="#{calendarBean.searched or not calendarBean.event.editable}"/>
            <h:outputText value=" " />
            
            <h:outputLabel for="visibility" value="Public:" />
            <h:selectBooleanCheckbox id="visibility" value="#{calendarBean.event.visibility}" disabled="#{calendarBean.searched or not calendarBean.event.editable}"/>
            <h:outputText value=" " />
            
            <h:outputLabel for="invite" value="Participants:" />
            <p:autoComplete id="invite" multiple="true" value="#{calendarBean.selectedUsers}" completeMethod="#{calendarBean.complete}"
                            var="theme" itemLabel="#{theme.email}" itemValue="#{theme}" converter="themeConverter" forceSelection="true" rendered="#{not calendarBean.searched and calendarBean.event.editable and not calendarBean.event.existingEvent}">
                <p:column>
                    <h:outputText value="#{theme.email}" />
                </p:column>
            </p:autoComplete>
            <ui:repeat var="u" value="#{calendarBean.event.participantsList}" rendered="#{(calendarBean.event.visibility and calendarBean.searched) or not calendarBean.event.editable or calendarBean.event.existingEvent}">
                <h:outputText value="#{u};" />
            </ui:repeat>
            <h:outputText value="Not Visible" rendered="#{not calendarBean.event.visibility and calendarBean.searched}" />
            <h:outputText value=" " />
            
            <h:outputText value="Weather: " />
            <h:outputText value="#{calendarBean.event.weather}" rendered="#{calendarBean.event.editable and not calendarBean.searched}" />
            <h:outputText value="#{calendarBean.event.weather}" rendered="#{(calendarBean.event.visibility and calendarBean.searched) or not calendarBean.event.editable}" />
            <h:outputText value="Not Visible" rendered="#{not calendarBean.event.visibility and calendarBean.searched}" />
            <h:outputText value=" " />
            
            <p:commandButton type="reset" value="Reset" rendered="#{calendarBean.event.editable and not calendarBean.searched}" />
            <p:commandButton id="addButton" value="Save" actionListener="#{calendarBean.addEvent}" 
                             oncomplete="PF('myschedule').update();PF('eventDialog').hide();"
                             rendered="#{calendarBean.event.editable and not calendarBean.searched}" update="messages"/>
            <p:commandButton id="deleteButton" value="Delete" actionListener="#{calendarBean.deleteEvent}" oncomplete="PF('myschedule').update();PF('eventDialog').hide();" rendered="#{calendarBean.event.editable and not calendarBean.searched}" />
        </h:panelGrid>
    </p:dialog>        
        </h:form>  
 
    
        
    </h:body>
</html>

